package com.tsing.bms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsing.bms.service.IHouseService;
import com.tsing.bms.vo.req.*;
import com.tsing.bms.vo.resp.HouseRageRespVo;
import com.tsing.bms.vo.resp.HouseRespVo;
import com.tsing.bms.vo.resp.IdAndNameRespVo;
import com.tsing.common.annotations.SystemLog;
import com.tsing.common.utils.ResultUtil;
import com.tsing.common.vo.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
@Api(tags = "房屋管理")
@RestController
@RequestMapping("/house")
public class HouseController {

    @Autowired
    private IHouseService houseService;

    @PostMapping("/addHouse")
    @ApiOperation(value = "新增房屋")
    @SystemLog(description = "新增房屋")
    public ResultData addHouse(@Validated @RequestBody HouseAddReqVo reqVo) {
        houseService.addHouse(reqVo);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteHouse")
    @ApiOperation(value = "删除房屋")
    @SystemLog(description = "删除房屋")
    public ResultData deleteHouse(@Validated @RequestBody IdsReqVo reqVo) {
        houseService.deleteHouse(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getHouse")
    @ApiOperation(value = "获取单个房屋信息")
    @SystemLog(description = "获取单个房屋信息")
    public ResultData<HouseRespVo> getHouseById(@Validated IdReqVo reqVo) {
        return ResultUtil.success(houseService.getHouseById(reqVo));
    }

    @PutMapping("/updateHouse")
    @ApiOperation(value = "修改房屋信息")
    @SystemLog(description = "修改房屋信息")
    public ResultData updateHouse(@Validated @RequestBody HouseUpdateReqVo reqVo) {
        houseService.updateHouse(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/housePage")
    @ApiOperation(value = "房屋分页")
    @SystemLog(description = "房屋分页")
    public ResultData<Page<HouseRageRespVo>> housePage(@Validated HousePageReqVo reqVo) {
        return ResultUtil.success(houseService.housePage(reqVo));
    }

    @PostMapping("/updateBalance")
    @ApiOperation(value = "充值余额")
    @SystemLog(description = "充值余额")
    public ResultData updateBalance(@Validated @RequestBody UpdateBalanceReqVo reqVo) {
        houseService.updateBalance(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/userList")
    @ApiOperation(value = "用户列表")
    @SystemLog(description = "用户列表")
    public ResultData<List<IdAndNameRespVo>> userList(@Validated NameReqVo reqVo) {
        return ResultUtil.success(houseService.userList(reqVo));
    }

}
